/*
 * SceneManager.h
 *
 *  Created on: 2009/01/19
 *      Author: elecgon
 */

#ifndef SCENEMANAGER_H_
#define SCENEMANAGER_H_

#include <vector>
#include "core/Color.h"
#include "RenderObjectContainer.h"
#include "core/ISingleton.h"
#include "Quadtree.h"
#include "Camera.h"
#include "sqplus/sqplus.h"
using namespace SqPlus;


class SceneManager : public ISingleton<SceneManager>
{
public:
	static const uint32 _DEFAULT_CAMERA = 0;

public:
	SceneManager();
	virtual ~SceneManager();

public:
	inline RenderObjectContainer* getRenderRoot() const { return mRenderRoot; }

	Camera* getActiveCamera();
	Camera* getCamera(uint32 idx);
	inline const uint32 getCameraCount() const { return (uint32)mCameras.size(); }

	void addCamera(Camera* c);
	void subCamera(Camera* c);

	void clear();
	void render();

private:
	bool isThereSameCamera(Camera* c);
	static bool sortRenderListByOrigin(Renderable* left, Renderable* right);

public:
	static SceneManager& GetInstance()
	{
		assert(m_pInstance);
		return *m_pInstance;
	}
	static SceneManager* GetInstancePtr()
	{
		return m_pInstance;
	}

private:
	RenderObjectContainer* 	mRenderRoot;

	Color					mClearColor;
	vector<Camera*>			mCameras;
	uint32					mActiveCamera;
};

//must be declared here
DECLARE_INSTANCE_TYPE(SceneManager)

#endif /* SCENEMANAGER_H_ */
